﻿package mortal.component.window
{
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.display.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.interfaces.*;

    public class SpecialWindow extends Window
    {
        protected var _bg:ScaleBitmap;
        protected var _titleBg:GImageBitmap;
        protected var _titleImage:GImageBitmap;
        protected var _peddingLeft:int = 5;
        protected var _titleLabel:TextField;
        protected var _title:DisplayObject;
        protected var _winTitleName:String;
        protected var _titleChange:Boolean = false;

        public function SpecialWindow(param1:ILayer = null)
        {
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.addBg();
            this.addTitleBg();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._bg)
            {
                this._bg.dispose(param1);
                this._bg = null;
            }
            if (this._titleBg)
            {
                this._titleBg.dispose(param1);
                this._titleBg = null;
            }
            if (this._titleImage)
            {
                this._titleImage.dispose(param1);
                this._titleImage = null;
            }
            return;
        }// end function

        private function resetTitle() : void
        {
            if (this._titleLabel)
            {
                this._titleLabel.setTextFormat(GlobalStyle.windowTitle);
                this._titleLabel.autoSize = TextFieldAutoSize.CENTER;
                this._titleLabel.htmlText = this._titleLabel.htmlText;
            }
            return;
        }// end function

        public function get title()
        {
            return this._title;
        }// end function

        public function set title(param1) : void
        {
            if (this._title && this._title.parent)
            {
                this._title.parent.removeChild(this._title);
                this._title = null;
            }
            if (param1 is DisplayObject)
            {
                this._winTitleName = DisplayObject(param1).name;
                this._title = param1;
                _titleSprite.addChild(this._title);
            }
            else if (param1 is String)
            {
                this._winTitleName = param1;
                this._titleLabel = new TextField();
                this._titleLabel.mouseEnabled = false;
                this._titleLabel.embedFonts = true;
                this._titleLabel.defaultTextFormat = GlobalStyle.windowTitle;
                this._titleLabel.selectable = false;
                this._titleLabel.filters = [FilterConst.titleFilter, FilterConst.titleShadowFilter, FilterConst.titleGradientBevelFilter];
                this._titleLabel.autoSize = TextFieldAutoSize.LEFT;
                this._titleLabel.htmlText = param1;
                this._titleLabel.antiAliasType = AntiAliasType.ADVANCED;
                this._titleLabel.sharpness = 100;
                this._titleLabel.gridFitType = GridFitType.SUBPIXEL;
                this._titleLabel.thickness = 100;
                this._title = this._titleLabel;
                _titleSprite.addChild(this._titleLabel);
                ResManager.instance.registerTitle(this.resetTitle);
            }
            _titleSprite.x = -_contentTopOf3DSprite.x + _contentX + this._peddingLeft;
            _titleSprite.y = -_contentTopOf3DSprite.y + _contentY;
            this._titleChange = true;
            this.updateDisplayList();
            return;
        }// end function

        override protected function updateDisplayList() : void
        {
            var _loc_1:Number = NaN;
            super.updateDisplayList();
            if (this._titleChange)
            {
                this._titleChange = false;
                _loc_1 = 68;
                if (this._title)
                {
                    this._title.y = 10;
                    this._title.x = (this.width - this._title.width) / 2;
                }
            }
            return;
        }// end function

        public function get winTitleName() : String
        {
            return this._winTitleName;
        }// end function

        public function set winTitleName(param1:String) : void
        {
            this._winTitleName = param1;
            return;
        }// end function

        protected function loadTitleComplete() : void
        {
            if (this._titleImage)
            {
                this._titleImage.x = (this.width - this._titleImage.width + this._peddingLeft * 2) * 0.5;
                this._titleImage.y = 3;
            }
            return;
        }// end function

        protected function set titleBitmapData(param1:BitmapData) : void
        {
            if (this._titleImage == null)
            {
                this._titleImage = UIFactory.gImageBitmap("", 0, 0, this);
            }
            this._titleImage.onLoadCompl = null;
            this._titleImage.bitmapData = param1;
            this.loadTitleComplete();
            return;
        }// end function

        protected function set titleImageUrl(param1:String) : void
        {
            if (this._titleImage == null)
            {
                this._titleImage = UIFactory.gImageBitmap("", 0, 0, this);
            }
            this._titleImage.onLoadCompl = this.loadTitleComplete;
            this._titleImage.imgUrl = param1;
            return;
        }// end function

        protected function addBg() : void
        {
            this._bg = UIFactory.bg(0, -18, this.width, this.height, this, ImagesConst.WindowBg3);
            return;
        }// end function

        protected function addTitleBg() : void
        {
            this._titleBg = UIFactory.gImageBitmap(ImagesConst.WindowTitleBg, 0, -52, this);
            return;
        }// end function

        override protected function updateSize() : void
        {
            super.updateSize();
            if (this._bg)
            {
                this._bg.setSize(this.width + this._peddingLeft * 2, this.height + 18);
                this._bg.x = -this._peddingLeft;
                this._bg.y = -18;
            }
            if (this._titleBg)
            {
                this._titleBg.x = (this.width - 257 + this._peddingLeft * 2) * 0.5 + 2;
                this._titleBg.y = -52;
            }
            if (_closeBtn)
            {
                _closeBtn.x = this.width - _closeBtn.width - 5 - this._peddingLeft * 2;
                _closeBtn.y = 5;
            }
            return;
        }// end function

    }
}
